package com.ruoyi.system.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.Mis;
import com.ruoyi.system.service.IMisService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * misController
 *
 * @author baifj
 * @date 2020-10-31
 */
@Controller
@RequestMapping("/system/mis")
public class MisController extends BaseController {
    private final String prefix = "system/mis";

    @Autowired
    private IMisService misService;

    @RequiresPermissions("system:mis:view")
    @GetMapping()
    public String mis() {
        return prefix + "/mis";
    }

    /**
     * 查询mis列表
     */
    @RequiresPermissions("system:mis:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(Mis mis) {
        startPage();
        List<Mis> list = misService.selectMisList(mis);
        return getDataTable(list);
    }

    /**
     * 导出mis列表
     */
    @RequiresPermissions("system:mis:export")
    @Log(title = "mis", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(Mis mis) {
        List<Mis> list = misService.selectMisList(mis);
        ExcelUtil<Mis> util = new ExcelUtil<Mis>(Mis.class);
        return util.exportExcel(list, "mis");
    }

    /**
     * 新增mis
     */
    @GetMapping("/add")
    public String add() {
        return prefix + "/add";
    }

    /**
     * 新增保存mis
     */
    @RequiresPermissions("system:mis:add")
    @Log(title = "mis", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(Mis mis) {
        return toAjax(misService.insertMis(mis));
    }

    /**
     * 修改mis
     */
    @GetMapping("/edit/{a1}")
    public String edit(@PathVariable("a1") String a1, ModelMap mmap) {
        Mis mis = misService.selectMisById(a1);
        mmap.put("mis", mis);
        return prefix + "/edit";
    }

    /**
     * 修改保存mis
     */
    @RequiresPermissions("system:mis:edit")
    @Log(title = "mis", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(Mis mis) {
        return toAjax(misService.updateMis(mis));
    }

    /**
     * 删除mis
     */
    @RequiresPermissions("system:mis:remove")
    @Log(title = "mis", businessType = BusinessType.DELETE)
    @PostMapping("/remove")
    @ResponseBody
    public AjaxResult remove(String ids) {
        return toAjax(misService.deleteMisByIds(ids));
    }
}
